/*
 * @Descripttion: 
 * @version: 1.0
 * @Author: 任静
 * @Date: 2020-11-13 13:41:39
 * @LastEditors: 任静
 * @LastEditTime: 2020-11-13 21:52:16
 */
/*
 * @Descripttion: 
 * @version: 1.0
 * @Author: 任静
 * @Date: 2020-11-11 16:18:16
 * @LastEditors: 任静
 * @LastEditTime: 2020-11-12 19:44:43
 */
/*
 * @Descripttion: 
 * @version: 1.0
 * @Author: 任静
 * @Date: 2020-11-11 19:57:59
 * @LastEditors: 任静
 * @LastEditTime: 2020-11-11 21:15:03
 */
import {
    getHotSearch,
    getSearch,
    getSearchTips
} from '@/api/index'
const state = {
    hotList: [],
    rankList: [],
    articleList: [],
    searchTipList: [],
    searchHistory: []
}
const mutations = {
    updateHotList(state, payload) {
        state.hotList = payload

    },
    updateSearchList(state, payload) {
        state.rankList = payload.rankList
        state.articleList = payload.articleList

    },
    updateSearchTips(state, payload) {
        state.searchTipList = payload.dataList
        console.log(payload)

    },
    updateSearchHistory(state, payload) {
        if (state.searchHistory.indexOf(payload.item) === -1) {
            state.searchHistory.push(payload.item)
        } else {
            state.searchHistory.splice(state.searchHistory.indexOf(payload.item), 1)
            state.searchHistory.push(payload.item)
        }
    },
    updateDeleteSearch(state) {
        state.searchHistory.length = 0
        console.log(111, state.searchHistory)
    }
}
const actions = {
    async getHotList({
        commit
    }, payload) {
        let res = await getHotSearch(payload);
        commit("updateHotList", res.dataList)
    },
    async getSearchList({
        commit
    }, payload) {
        let res = await getSearch(payload);
        commit("updateSearchList", res)
    },
    async getSearchTipList({
        commit
    }, payload) {
        let res = await getSearchTips(payload.dataList);
        commit("updateSearchTips", res)
    },
    async getSearchHistory({
        commit
    }, payload) {
        commit('updateSearchHistory', payload)
    },
    async deleteSearchHistory({
        commit
    }) {
        commit('updateDeleteSearch')
    }
}
export default {
    namespaced: true,
    state,
    mutations,
    actions
}